#ifndef FFMPEGEXTRA_EYERWASMHTTPFETCH_FETCHEVENT_HPP
#define FFMPEGEXTRA_EYERWASMHTTPFETCH_FETCHEVENT_HPP

#include "EyerWASMCommon/EyerWASMEvent.hpp"

namespace Eyer
{
    class EyerWASMHttpFetch_FetchEvent : public EyerWASMEvent
    {
    public:
        EyerWASMHttpFetch_FetchEvent(const std::string & _url, int64_t _rangeStart, int64_t _rangeEnd);
        ~EyerWASMHttpFetch_FetchEvent();

        virtual int Run() override;

        int EyerWASMHttpFetch_FetchEvent_Fetch_On_Header_Recv(int httpStatus, int64_t contentLength, int64_t rangeLength);
        int EyerWASMHttpFetch_FetchEvent_Fetch_On_Body_Recv(uint8_t * buf, int bufSize);
        int EyerWASMHttpFetch_FetchEvent_Fetch_On_Fail();

        bool isHttpHeaderRecved();

        int GetHttpStatus();

        int GetBufferSize();
        uint8_t * GetBufferPtr();

        int64_t GetContentLength();
        int64_t GetRangeLength();

        int GetFetchAbortKey();

    private:
        std::string url = "";
        int64_t rangeStart = -1;
        int64_t rangeEnd = -1;

        std::atomic<bool> isHeaderRecved {false};
        int httpStatus = 0;
        int64_t contentLength = 0;
        int64_t rangeLength = 0;

        uint8_t * buf = nullptr;
        int bufSize = 0;

        int fetchAbortKey = 0;
    };
}

#endif //FFMPEGEXTRA_EYERWASMHTTPFETCH_FETCHEVENT_HPP
